package rwt.server.handlers;

import rwt.server.*;
import rwt.server.RailroadMessages.PutTrainStateMsg;
import rwt.server.WebMessages.PutTrainState;
import rwt.server.core.*;

public class PutTrainStateHandler extends MessageHandler<PutTrainStateMsg>
{
	@Override
	public void handle(PutTrainStateMsg message, IConnection source) throws Exception
	{
		int trainId = RailServer.getTrainManager().slotToTrainId(message.slot);
		PutTrainState webMsg = new PutTrainState(trainId, message.state);
		
		// TODO: Send only to the client (if any) who has the throttle controlling this train
		RailServer.getClientManager().sendToAll(webMsg);
	}
}
